<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ChangeHospitalInfoTableChangeFieldBanner extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $infos = \App\Models\HospitalInfo::query()
            ->get();
        foreach ($infos as $info) {
            $info->banner = collect($info->banner)->toJson();
            $info->save();
        }

        Schema::table('hospital_infos', function (Blueprint $table) {
            $table->json('banner')->nullable()->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('hospital_infos', function (Blueprint $table) {
            $table->string('banner')->nullable(false)->change();
        });
    }
}
